<template>
	<view class="configuration">
		<view class="top-box">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>审核</el-breadcrumb-item>
				<el-breadcrumb-item>{{ getBreadcrumb }}</el-breadcrumb-item>
			</el-breadcrumb>
			
			<view class="header-serch flex ac jcsb">
				<!-- 媒体审核 or 广告位审核 -->
				<view class="search-box flex ac" v-if="second == 1 || !second">
					<view class="search flex ac">
						<view class="search-title min-w72" :class="{ 'min-w86': second }">{{ second? '广告位':'媒体' }}名称：</view>
						<el-input v-model="name" :placeholder="second? '请输入广告位名称':'请输入媒体名称'" style="height: 32px;"></el-input>
					</view>
					<view class="search flex ac">
						<view class="search-title min-w108" :class="{ 'min-w116': second }">{{ second? '广告位':'媒体' }}状态：</view>
						<el-select v-model="value" placeholder="请选择">
							<el-option
							  v-for="t in selectArr"
							  :key="t.value"
							  :label="t.label"
							  :value="t.value">
							</el-option>
						</el-select>
					</view>
					<view class="search-btn">
						<el-button type="primary" class="search-button" @click='search'>查询</el-button>
					</view>
				</view>
				
				<!-- 用户审核 -->
				<view class="search-box flex ac" v-if="second == 2">
					<view class="search flex ac">
						<view class="search-title min-w58">姓名：</view>
						<el-input v-model="realName" placeholder="请输入姓名" style="height: 32px;"></el-input>
					</view>
					<view class="search flex ac">
						<view class="search-title min-w100">公司名称：</view>
						<el-input v-model="companyName" placeholder="请输入公司名称" style="height: 32px;"></el-input>
					</view>
					<view class="search flex ac">
						<view class="search-title min-w100">用户类型：</view>
						<el-select v-model="value2" placeholder="请选择">
							<el-option
							  v-for="t in selectArr2"
							  :key="t.value"
							  :label="t.label"
							  :value="t.value">
							</el-option>
						</el-select>
					</view>
					<view class="search-btn">
						<el-button type="primary" class="search-button" @click='search'>查询</el-button>
					</view>
				</view>
				
				<!-- 投放审核 -->
				<view class="search-box flex ac" v-if="second == 3">
					<view class="search flex ac">
						<view class="search-title min-w72">链接名称：</view>
						<el-input v-model="name" placeholder="请输入链接名称" style="height: 32px;"></el-input>
					</view>
					<view class="search flex ac">
						<view class="search-title min-w100">审核状态：</view>
						<el-select v-model="value3" placeholder="请选择">
							<el-option
							  v-for="t in selectArr3"
							  :key="t.value"
							  :label="t.label"
							  :value="t.value">
							</el-option>
						</el-select>
					</view>
					<view class="search-btn">
						<el-button type="primary" class="search-button" @click='search'>查询</el-button>
					</view>
				</view>
				
				<!-- <el-button class="add-user" type="primary" @click='openDelog(0)' v-if="!second">+ 新增媒体</el-button> -->
			</view>
			
			<el-table 
				:data="Table.TableDataList" 
				style="width: 100%;" 
				height="calc(100vh - 298px)"
				stripe
				:header-cell-style="{background:'#E9ECEE',color:'#16171F'}">
				<el-table-column 
					show-overflow-tooltip 
					:prop="item.prop" 
					:label="item.label" 
					v-for="(item,index) in newTitleList"
					:key="index">
					<template slot-scope="scope">
						<!-- 每一项的值 -->
						<span v-if="item.prop && item.prop != 'status' && item.prop != 'mediaStatus' && item.prop != 'userStatus' && item.prop != 'userType' && item.prop != 'tpStatus' && item.prop != 'auditStatus'">{{ (item.prop == 'createTime' || item.prop == 'updateTime' || item.prop == 'updateDate')? new Date(scope.row[item.prop]).format():scope.row[item.prop] }}</span>
						
						<span v-if="item.prop && item.prop == 'mediaStatus'" class="start-color" :class="{ 'yes': scope.row[item.prop] == 0, 'no': (scope.row[item.prop] == 1 || scope.row[item.prop] == 3) }">{{ getMediaStatus(scope.row[item.prop]) }}</span>
						
						<!-- 广告位审核 审核状态  -->
						<span v-if="item.prop && item.prop == 'status'" class="start-color" :class="{ 'no': scope.row[item.prop] == 3 }">{{ scope.row[item.prop] == 2? '待审核':(scope.row[item.prop] == 3? '审核拒绝':'默认') }}</span>
						
						<!-- 用户审核 审核状态 -->
						<span v-if="item.prop && item.prop == 'userStatus'" class="start-color" :class="{ 'no': scope.row[item.prop] == 3 }">{{ scope.row[item.prop] == 2? '待审核':(scope.row[item.prop] == 3? '审核拒绝':'默认') }}</span>
						<!-- 用户审核 用户类型 -->
						<span v-if="item.prop && item.prop == 'userType'">{{ getUserType(scope.row) }}</span>
						<!-- <span v-if="item.prop && item.prop == 'userType'">{{ scope.row[item.prop] == 2? '广告主':(scope.row[item.prop] == 1? '流量主':'默认') }}</span> -->
						
						<!-- 投放审核 链接状态 -->
						<span v-if="item.prop && item.prop == 'tpStatus'" class="start-color" :class="{ 'yes': scope.row[item.prop] == 0, 'no': scope.row[item.prop] != 0 }">{{ scope.row[item.prop] == 0? '启用':'禁用' }}</span>
						<!-- 投放审核 审核状态 -->
						<span v-if="item.prop && item.prop == 'auditStatus'" class="start-color" :class="{ 'yes': scope.row[item.prop] == 0, 'no': scope.row[item.prop] == 1 }">{{ getAuditStatus(scope.row[item.prop]) }}</span>
						
						<!-- 操作项 -->
						<!-- 媒体审核 -->
						<view v-if="!item.prop && !second">
							<el-button class="start-color" :class="{ 'color-ccc': scope.row['mediaStatus'] == 3 }" :disabled="scope.row['mediaStatus'] == 3" @click="updateClick(scope.row, scope.$index, 1)" type="text" size="small">审核</el-button>
							<!-- <el-button class="del-color" @click="delClick(scope.row, 0)" type="text" size="small">删除</el-button> -->
						</view>
						<!-- 广告位审核 -->
						<view v-if="!item.prop && second == 1">
							<el-button class="start-color" :class="{ 'color-ccc': scope.row['status'] == 3 }" :disabled="scope.row['status'] == 3" @click="updateClick(scope.row, scope.$index)" type="text" size="small">审核</el-button>
							<el-button class="del-color" @click="delClick(scope.row, 1)" type="text" size="small">删除</el-button>
						</view>
						<!-- 用户审核 -->
						<view v-if="!item.prop && second == 2">
							<el-button class="start-color" @click="userAuditClick(scope.row, 0)" :class="{ 'color-ccc': scope.row['userStatus'] == 3 }" :disabled="scope.row['userStatus'] == 3" type="text" size="small">审核</el-button>
						</view>
						<!-- 投放审核 -->
						<view v-if="!item.prop && second == 3">
							<el-button class="start-color" @click="userAuditClick(scope.row, 1)" :class="{ 'color-ccc': scope.row['auditStatus'] == 1 }" :disabled="scope.row['auditStatus'] == 1" type="text" size="small">审核</el-button>
						</view>
					</template>
				</el-table-column>
			</el-table>
		</view>
		<view class="footer">
			<el-pagination  
				@size-change="handleSizeChange" 
				@current-change="handleCurrentChange"
				:current-page="Table.page"  
				layout="total, prev, pager, next, jumper, sizes" 
				background 
				:total="Table.count"
				:page-sizes="[10, 12]" 
				:page-size.sync="Table.limit">
			</el-pagination>
			<view class="pageLimit">当前显示{{Table.limit}}条/页</view>
		</view>
		
		<confirm @confirmFlagClick="confirmFlagClick" :confirmFlag="confirmFlag" :title="confirmTitle"></confirm>
		<mediaDialog :dialogVisible="addUserDialogFlag" @closeDialog="closeDialog" :item="currentUpdate" :title="addDialogTitle"></mediaDialog>
		<userAuditDialog :dialogVisible="addUserDialogFlag2" @closeDialog="closeDialog2" :title="guanggaoOrUser" :item="currentAudit"></userAuditDialog>
		<!-- <advertisingSpaceAudit :dialogVisible="advertisingSpaceAuditFlag" @closeDialog="closeDialog3" :title="advertisingSpaceAuditTitle" :item="advertisingSpaceAuditItem"></advertisingSpaceAudit> -->
	</view>
</template>

<script>
	import { Request } from '../model/request.js'
	import { Util } from '../utils/util.js'
	import confirm from './dialog/confirm.vue'
	import mediaDialog from './dialog/mediaDialog.vue'
	import userAuditDialog from './dialog/userAuditDialog.vue'
	// import advertisingSpaceAudit from './dialog/advertisingSpaceAudit.vue'
	 
	export default {
		components: { confirm, mediaDialog, userAuditDialog },
		
		props: {
			second: {
				type: [String, Number],
				default: 0
			}
		},
		
		computed: {
			getBreadcrumb() {
				let c = '媒体审核'
				if (this.second == 1) {
					c = '广告位审核'
				} else if (this.second == 2) {
					c = '用户审核'
				} else {
					c = '投放审核'
				}
				return c
			},
			
			newTitleList() {
				if (this.second == 1) {
					return this.Table.titleList1
				} else if (this.second == 2) {
					return this.Table.titleList2
				} else if (this.second == 3) {
					return this.Table.titleList3
				} else {
					return this.Table.titleList
				}
			}
		},
		
		data() {
			return {
				phone: '',
				name: '',
				realName: '',
				companyName: '',
				selectArr: [
					{
					  value: '',
					  label: '全部'
					}, {
					  value: '2',
					  label: '待审核'
					}, {
					  value: '3',
					  label: '审核拒绝'
					}
				],
				value: '',
				selectArr2: [
					{
					  value: '',
					  label: '全部'
					},
					{
					  value: '1',
					  label: '流量主'
					},
					{
					  value: '2',
					  label: '广告主'
					},
					{
					  value: '3',
					  label: 'DMP'
					}
				],
				value2: '',
				selectArr3: [
					{
					  value: '',
					  label: '全部'
					}, {
					  value: '0',
					  label: '审核通过'
					}, {
					  value: '1',
					  label: '审核拒绝'
					}, {
					  value: '2',
					  label: '待审核'
					}
				],
				value3: '',
				Table: {
					titleList: [{
							prop: "mediaName",
							label: "媒体名称"
						},
						{
							prop: "mediaSp",
							label: "系统平台"
						},
						{
							prop: "mediaKeyword",
							label: "媒体关键字"
						},
						{
							prop: "websiteName",
							label: "网站域名"
						},
						{
							prop: "mediaStatus",
							label: "状态"
						},
						{
							prop: "createTime",
							label: "创建时间"
						},
						// {
						// 	prop: "secretkey",
						// 	label: "appSecret"
						// },
						// {
						// 	prop: "appkey",
						// 	label: "appKey"
						// },
						{
							// prop: "mediaStatus",
							label: "操作"
						},
					],
					titleList1: [{
							prop: "adName",
							label: "广告位名称"
						},
						{
							prop: "adType",
							label: "广告位类型"
						},
						{
							prop: "mediaName",
							label: "所属媒体"
						},
						// {
						// 	prop: "specification",
						// 	label: "广告位规格"
						// },
						{
							prop: "status",
							label: "链接状态"
						},
						// {
						// 	prop: "link",
						// 	label: "广告链接"
						// },
						// {
						// 	prop: "uvPrice",
						// 	label: "每UV价格"
						// },
						// {
						// 	prop: "pvPrice",
						// 	label: "每PV价格"
						// },
						{
							prop: "updateDate",
							label: "更新时间"
						},
						{
							// prop: "mediaStatus",
							label: "操作"
						}
					],
					titleList2: [{
							prop: "userName",
							label: "账户名"
						},
						{
							prop: "phone",
							label: "联系电话"
						},
						{
							prop: "email",
							label: "邮箱"
						},
						{
							prop: "realName",
							label: "姓名"
						},
						{
							prop: "companyName",
							label: "公司名称"
						},
						{
							prop: "userStatus",
							label: "审核状态"
						},
						{
							prop: "userType",
							label: "用户类型"
						},
						{
							// prop: "mediaStatus",
							label: "操作"
						}
					],
					titleList3: [{
							prop: "id",
							label: "链接ID"
						},
						{
							prop: "tpName",
							label: "链接名称"
						},
						{
							prop: "link",
							label: "链接"
						},
						{
							prop: "channel",
							label: "渠道"
						},
						// {
						// 	prop: "tpStatus",
						// 	label: "链接状态"
						// },
						{
							prop: "auditStatus",
							label: "审核状态"
						},
						{
							prop: "uvPrice",
							label: "UV价格"
						},
						{
							prop: "priceDay",
							label: "日消耗量"
						},
						{
							prop: "createTime",
							label: "创建时间"
						},
						{
							prop: "updateTime",
							label: "更新时间"
						},
						{
							label: "操作"
						}
					],
					TableDataList: [],
					result: '',
					page: 1,
					limit: 10,
					count: 0
				},
				
				confirmFlag: false,
				confirmTitle: '',
				confirmType: '',
				currentDelItem: {},
				
				addUserDialogFlag: false,
				addDialogTitle: '',
				currentUpdate: {},
				
				addUserDialogFlag2: false,
				currentAudit: {},
				guanggaoOrUser: '',
				
				advertisingSpaceAuditTitle: '',
				advertisingSpaceAuditItem: {},
				advertisingSpaceAuditFlag: false
			}
		},
		
		mounted() {
			this.initTable()
		},
		
		watch: {
			second(newVal, oldVal) {
				this.phone = ''
				this.name = ''
				this.realName = ''
				this.companyName = ''
				this.value = this.value2 = this.value3 = ''
				this.Table.page = 1
				this.Table.limit = 10
				this.Table.count = 0
				this.initTable()
			},
			value() {
				this.initTable()
			},
			value2() {
				this.initTable()
			},
			value3() {
				this.initTable()
			}
		},
		
		methods: {
			getUserType(e) {
				let { typeCode, userType } = e
				if (userType == 1) {
					return '流量主'
				} else if (userType == 2) {
					if (typeCode == 1) {
						return '广告主-主体账户'
					} else if (typeCode == 2) {
						return '广告主-代理'
					} else if (typeCode == 3) {
						return '广告主-客户'
					}
					// return '广告主'
				} else if (userType == 3) {
					if (typeCode == 1) {
						return 'DMP-主体账户'
					} else if (typeCode == 2) {
						return 'DMP-代理'
					} else if (typeCode == 3) {
						return 'DMP-客户'
					} 
				} else {
					return '其他'
				}
			},
			
			getMediaStatus(i) {
				if (i == 1) {
					return '不可用'
				} else if (i == 2) {
					return '待审核'
				} else if (i == 3) {
					return '审核拒绝'
				} else {
					return '可用'
				}
			},
			
			getAuditStatus(i) {
				if (i == 0) {
					return '审核通过'
				} else if (i == 1) {
					return '审核拒绝'
				} else if (i == 2) {
					return '待审核'
				}
			},
			
			search() {
				this.initTable()
			},
			
			async initTable(page) {
				this.Table.TableDataList = []
				if (!Util.isNull(page)) {
					this.Table.page = page
				} else {
					this.Table.page = 1
				}
				let res
				if (this.second == 1) {
					res = await Request.PLACEFINDALLVERIFY(this.Table.page, this.Table.limit, this.name, this.value)
				} else if (this.second == 2) {
					res = await Request.USERALLVERIFY(this.Table.page, this.Table.limit, this.companyName, this.realName, this.value2)
				} else if (this.second == 3) {
					res = await Request.THIRDFINDALLVERIFY(this.Table.page, this.Table.limit, this.name, this.value3)
				} else { // 媒体审核
					res = await Request.MEDIAFINDALVERIFYL(this.Table.page, this.Table.limit, this.name, this.value)
				}
				console.log(res, 'resswss')
				if (!Util.isNull(res)) {
					this.Table.TableDataList = res.data.records
					this.Table.count = res.data.total
				} else {
					this.Table.TableDataList = null
				}
				
				// a href="http://192.168.3.181:8080/file/download?fileUrl= "
			},
			
			openDelog(i) {
				// if (i) {
				// 	this.addDialogTitle = '新增链接'
				// } else {
				// 	this.addDialogTitle = '创建用户'
				// }
				this.addDialogTitle = '新增媒体'
				this.addUserDialogFlag = true
			},
			
			closeDialog(flag) {
				this.currentUpdate = {}
				this.addUserDialogFlag = false
				if (typeof flag != 'function' && flag) {
					this.initTable()
				}
			},
			
			closeDialog2(flag) {
				this.currentAudit = {}
				this.addUserDialogFlag2 = false
				if (typeof flag != 'function' && flag) {
					this.initTable()
				}
			},
			
			closeDialog3(flag) {
				this.advertisingSpaceAuditItem = {}
				this.advertisingSpaceAuditFlag = false
				// if (typeof flag != 'function' && flag) {
				// 	this.initTable()
				// }
			},
			
			delClick(item, i) {
				if (i) { // 广告位
					this.confirmTitle = `确认删除广告位：${item.adName}`
				}
				//  else { // 媒体
				// 	this.confirmTitle = '确认删除用户？'
				// }
				this.confirmFlag = true
				this.currentDelItem = item
			},
			
			// 确认事件
			async confirmFlagClick(i) {
				if (i) { // 确认
					let res
					if (!this.second) { // 媒体审核
						console.log('媒体审核，确认了')
						// res = await Request.MEDIADEL(this.currentDelItem.id) 
					} else if (this.second == 1) { // 广告位审核
						console.log('广告位，确认了')
						res = await Request.PLACEDEL(this.currentDelItem.id)
						if (res.code == 200) {
							Util.showToast('删除成功')
							this.initTable()
						}
					} else { // 广告链接
						
					}
				}
				this.confirmFlag = false
			},
			
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
				this.initTable()
			},
			
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`);
				this.initTable(val)
			},
			
			// 广告位 or 媒体审核 点击
			updateClick(item, index, i) {
				if (i) { // 媒体
					this.addUserDialogFlag = true
					this.currentUpdate = item
					this.addDialogTitle = '审核'
				} else {
					this.currentAudit = item
					this.addUserDialogFlag2 = true
					this.guanggaoOrUser = '广告位审核'
				}
			},
			
			userAuditClick(item, i) {
				if (i) { // 投放审核
					this.guanggaoOrUser = '广告投放审核'
				} else { // 用户审核
					this.guanggaoOrUser = '审核用户'
				}
				this.currentAudit = item
				this.addUserDialogFlag2 = true
			}
		}
	}
</script>

<style scoped>
	.configuration {
		/* padding: 20px 40px 50px; */
		position: relative;
	}
	
	.top-box {
		padding: 20px 40px 0;
	}
	
	.header-serch {
		margin: 30px 0;
	}
	
	.search-title {
		/* width: 100px; */
		font-size: 14px;
		font-weight: 500;
		color: #16171F;
		text-align: right;
	}
	
	.search-btn {
		margin-left: 30px;
	}
	
	.footer {
		width: 100%;
		height: 40px;
		display: flex;
		align-items: center;
		/* position: absolute; */
		/* left: 0; */
		/* bottom: 0px; */
		justify-content: center;
		height: 130px;
		background: #FFFFFF;
		box-shadow: 0px -7px 9px 0px rgba(0, 0, 0, 0.02);
	}
	
	.del-color {
		color: #D1141F;
	}
	
	.start-color {
		color: #4A92FD;
	}
	
	.yes {
		color: #69BC2E;
	}
	
	.no {
		color: #D1141F;
	}
	
	>>> .el-input__inner{
		height: 32px;
	}
	
	.search-button, .add-user {
		font-size: 14px;
		height: 32px;
		line-height: 32px;
		padding-top: 0;
		padding-bottom: 0;
	}
	
	/* 选择框 行高 */
	>>> .el-input__icon {
		line-height: 28px;
	}
	
	.min-w58 {
		width: 54px;
	}
	
	.min-w72 {
		min-width: 72px;
	}
	
	.min-w86 {
		min-width: 86px;
	}
	
	.min-w100 {
		min-width: 100px;
	}
	
	.min-w108 {
		min-width: 108px;
	}
	
	.min-w116 {
		min-width: 116px;
	}
	
	.w74 {
		width: 74px;
	}
	
	.color-ccc {
		color: #CCCCCC;
	}
</style>
